package com.caikun.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.plaf.synth.SynthSeparatorUI;

import com.caikun.dao.UserinfosDao;
import com.caikun.entity.Userinfos;
import com.caikun.services.UserinfosService;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Servlet implementation class RegisterController
 */
public class RegisterController extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String bind =request.getParameter("bind");
		System.out.println(bind);
		String password= request.getParameter("password");
//		System.out.println(password);
//		System.out.println(bind+password);
		PrintWriter out = response.getWriter();
		Userinfos user = new Userinfos();
		UserinfosService us =new UserinfosService();
			int count =  us.findUserByBind(bind).size();
			if(bind==null&&password==null){
				out.write("{\"status\":\"000\"}");
			}else if(count==0){
				user.setBind(bind);
				user.setPassword(password);
//				System.out.println(user.getBind()+user.getPassword());
				us.save(user);
				out.println("{\"status\":\"666\"}");
				}else{
					out.println("{\"status\":\"444\"}");
				}
			out.flush();
			out.close();
		}
	}



